package com.kaiyidiannao.activity.login_or_registered;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.view.ActionBarView;

/**
 * Created by wzg on 14-4-14.
 */
public class LoginOrRegistered extends TabActivity {
    private TabHost tabHost;
    private TextView user_login;
    private TextView user_registered;
    private ActionBarView actionBarView;
    String classname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_or_registered);
        tabHost = this.getTabHost();
        final TabWidget tabWidget = tabHost.getTabWidget();
        Intent intent = getIntent();
        if (intent.getStringExtra("ClassName") != null) {
            classname = intent.getStringExtra("ClassName");
        }
        actionBarView = (ActionBarView) findViewById(R.id.login_actionBar);
        actionBarView.setTitle("登录或注册");

        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.login_bt, null);
        user_login = (TextView) view.findViewById(R.id.user_login);

        user_login.setText("登录");
        Intent intent1 = new Intent(this, UserLogin.class);
        if (classname != null && !"".equals(classname)) {
            intent1.putExtra("ClassName", classname);
        }
        tabHost.addTab(tabHost.newTabSpec("").setContent(intent1).setIndicator(view));
        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
            @Override
            public void onTabChanged(String tabId) {
                for (int i = 0; i < tabWidget.getChildCount(); i++) {
                    View vvv = tabHost.getTabWidget().getChildAt(i);
                    if (tabHost.getCurrentTab() == i) {
                        Log.d("00000000000", "0000000000000000");
                        vvv.setBackgroundResource(R.drawable.selector_bg);
                    } else {
                        Log.d("00000000000", "11111111111111111");
                        vvv.setBackgroundResource(R.drawable.selector_bg_01);
                    }
                }
            }
        });

        Intent intent2 = new Intent(this, UserRegistered.class);
        view = inflater.inflate(R.layout.login_registered, null);
        user_registered = (TextView) view.findViewById(R.id.user_registered);
        user_registered.setText("注册");
        tabHost.addTab(tabHost.newTabSpec("").setContent(intent2).setIndicator(view));
        tabHost.setCurrentTab(0);


    }
}
